lscpu command examples in Linux [Cheat Sheet] |
您所在的位置:网站首页 › print offline › lscpu command examples in Linux [Cheat Sheet] |
Topics we will cover
hide
Introduction to lscpu command
How to install lscpu
Columns in lscpu command output
Different examples to use lscpu command
Conclusion
What's Next
Further Reading
Introduction to lscpu command
lscpu is a command-line utility to display information about the CPU architecture. It reads the CPU architecture information from sysfs and /proc/cpuinfo files and prints in the terminal. The information includes the number of CPUs, threads, cores, sockets, and Non-Uniform Memory Access (NUMA) nodes. It also displays CPU caches and cache sharing, family, model, bogoMIPS, byte order, and stepping. How to install lscpu Most Linux distributions have lscpu pre-installed in the system. In case if it is not found, you can install lscpu from the default package management repositories. The lscpu command is part of the util-linux package. To install lscpu on CentOS, Fedora and RHEL $ sudo yum install util-linuxTo install lscpu on Ubuntu and Debian $ sudo apt-get install util-linuxColumns in lscpu command output The following columns are only displayed when lscpu is used with option -e or -p. CPU: The logical CPU number of a CPU as used by the Linux kernel. CORE: The logical core number. A core can contain several CPUs. SOCKET: The logical socket number. A socket can contain several cores. BOOK: The logical book number. A book can contain several sockets. NODE: The logical NUMA node number. A node may contain several books. DRAWER: The logical drawer number. A drawer may contain several nodes. CACHE: Information about how caches are shared between CPUs. POLARIZATION: It shows CPU dispatching mode on virtual hardware. The polarization can be: horizontal: The workload is spread across all available CPUs. vertical: The workload is concentrated on a few CPUs. ALSO READ 9 screen command Examples in Linux [Cheat Sheet]ADDRESS: The physical address of a CPU. CONFIGURED: It shows if the hypervisor has allocated the CPU to the virtual hardware. ONLINE: This shows whether the Linux instance currently makes use of the CPU. MAXMHZ: It shows the maximum MHz of the CPU. MINMHZ: It shows the minimum MHz of the CPU. Different examples to use lscpu command The syntax of lscpu command is: $ lscpu [options]Some available options in lscpu command are: -a: print both online and offline CPUs -b: print online CPUs only -c: print offline CPUs only -e: print in an extended readable format -p: print CPU information in parsable format
1. lscpu command to display complete CPU architecture information You can use lscpu command without any options to view the complete information of CPU architecture in the system. On some distributions, you can also use --physical argument to print the same information. $ lscpuSample Output: 2. lscpu command to display sizes in bytes -b or --bytes option prints size in bytes rather than in human-readable format. $ lscpu -bOR $ lscpu --bytesSample Output: 3. Display the CPU information in human-readable format with lscpu command You can use -e or --extended option to print the CPU information in an extended human-readable format. $ lscpu -eOR $ lscpu --extendedSample Output: ubuntu@golinux:~$ lscpu -e CPU NODE SOCKET CORE L1d:L1i:L2:L3 ONLINE 0 0 0 0 0:0:0:0 yesIf you want to limit the columns of the above output, you can use the following syntax. list is the name of the columns. $ lscpu -e=listOR $ lscpu --extended=listSample Output: ubuntu@golinux:~$ lscpu -e=cache L1d:L1i:L2:L3 0:0:0:0 ubuntu@golinux:~$ lscpu -e=cpu,core CPU CORE 0 0ALSO READ PSSH - 10 practical examples to use parallel SSH in Linux4. lscpu command to display CPU information in parsable format -p or --parse option optimizes the lscpu command output for easy parsing. The parsable format can be fed to other programs. $ lscpu -pOR $ lscpu --parseSample Output: ubuntu@golinux:~$ lscpu -p # The following is the parsable format, which can be fed to other # programs. Each different item in every column has an unique ID # starting from zero. # CPU,Core,Socket,Node,,L1d,L1i,L2,L3 0,0,0,0,,0,0,0,0You can also limit the columns using the following syntax. $ lscpu -p=listOR $ lscpu --parse=listSample Output: ubuntu@golinux:~$ lscpu -p=cpu,core # The following is the parsable format, which can be fed to other # programs. Each different item in every column has an unique ID # starting from zero. # CPU,Core 0,05. Display both online and offline CPUs with lscpu command -a or -all option is used to display both online and offline CPUs in the output. You can only use this option with -e or -p. $ lscpu -a [-e or -p]OR $ lscpu --all [-e or -p]Sample Output: ~]# lscpu --all -e CPU NODE SOCKET CORE L1d:L1i:L2:L3 ONLINE 0 0 0 0 0:0:0:0 yes 1 0 1 1 1:1:1:1 yes 2 0 2 2 2:2:2:2 yes 3 0 3 3 3:3:3:3 yes 4 0 4 4 4:4:4:4 yes 5 0 5 5 5:5:5:5 yes 6 0 6 6 6:6:6:6 yes 7 0 7 7 7:7:7:7 yes 8 0 8 8 8:8:8:8 yes 9 0 9 9 9:9:9:9 yes 10 0 10 10 10:10:10:10 yes 11 0 11 11 11:11:11:11 yes 12 0 12 12 12:12:12:12 yes 13 0 13 13 13:13:13:13 yes 14 0 14 14 14:14:14:14 yes 15 0 15 15 15:15:15:15 yes6. Display only online CPUs with lscpu command You can limit the output to online CPUs with options -b or --online. This option should be used with -e or -p. $ lscpu -b [-e or -p]OR $ lscpu --online [-e or -p]Sample Output: ~]# lscpu --online -e CPU NODE SOCKET CORE L1d:L1i:L2:L3 ONLINE 0 0 0 0 0:0:0:0 yes 1 0 1 1 1:1:1:1 yes 2 0 2 2 2:2:2:2 yes 3 0 3 3 3:3:3:3 yes 4 0 4 4 4:4:4:4 yes 5 0 5 5 5:5:5:5 yes 6 0 6 6 6:6:6:6 yes 7 0 7 7 7:7:7:7 yes 8 0 8 8 8:8:8:8 yes 9 0 9 9 9:9:9:9 yes 10 0 10 10 10:10:10:10 yes 11 0 11 11 11:11:11:11 yes 12 0 12 12 12:12:12:12 yes 13 0 13 13 13:13:13:13 yes 14 0 14 14 14:14:14:14 yes 15 0 15 15 15:15:15:15 yesALSO READ 15 usermod command examples in Linux [Cheat Sheet]7. lscpu command to display only offline CPUs You can use -c or --offline option to display only offline CPUs in the output. This option also works with -e or -p only. $ lscpu -c [-e or -p]OR $ lscpu --offline [-e or -p]Sample Output: There are no offline CPUs. ubuntu@golinux:~$ lscpu --offline -e ubuntu@golinux:~$8. lscpu command to display CPU information in JSON format You can use -J or --json option to print the CPU information in JSON format. $ lscpu -JOR $ lscpu --jsonSample Output: 9. lscpu command to display information about caches -C or --caches option prints the information about caches in an extended readable format. $ lscpu -COR $ lscpu --cachesSample Output: ubuntu@golinux:~$ lscpu --caches NAME ONE-SIZE ALL-SIZE WAYS TYPE LEVEL L1d 32K 32K 8 Data 1 L1i 32K 32K 8 Instruction 1 L2 256K 256K 4 Unified 2 L3 8M 8M 16 Unified 3Here, NAME: cache name ONE-SIZE: size of one cache ALL-SIZE: size of all system caches WAYS: ways of associativity TYPE: cache type LEVEL: cache level10. Use hexadecimal masks with lscpu command You can use hexadecimal masks to print CPU sets (for example, 0x3) using -x or --hex option. By default, lscpu prints the sets in list format (for example, 0,1). $ lscpu -xOR $ lscpu --hexSample Output: 11. lscpu command to read CPU information from directory -s or --sysroot option can gather CPU information from the directory, which is the system root of the Linux system. $ lscpu -s directoryOR $ lscpu --sysroot directorySample Output: ALSO READ 10+ lzop command examples in Linux [Cheat Sheet]12. Display all available columns with lscpu command You can use --output-all option to view all the available columns for --extended, --parse, and --caches. $ lscpu --output-all -eSample Output: 13. Save lscpu command output to a text file We can also save the output of lscpu command into a text file by appending the content using > sign or tee command: ~]# lscpu | tee /tmp/cpu.txt OR ~]# lscpu > /tmp/cpu.txtVerify the content of /tmp/cpu.txt file: ~]# cat /tmp/cpu.txtConclusion In this article, you have learned about the lscpu command and its usages in the Linux system. lscpu is a useful tool to gather CPU architecture information. If you still have any confusion, let us know in the comment section. What's Next 20+ lshw command examples in Linux [Cheat Sheet] Further Reading man page for lscpu command Views: 565 Can't find what you're searching for? Let us assist you. Enter your query below, and we'll provide instant results tailored to your needs. If my articles on GoLinuxCloud has helped you, kindly consider buying me a coffee as a token of appreciation. ![]() For any other feedbacks or questions you can send mail to [email protected] Thank You for your support!! |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |